package com.ninetaildemonfox.zdl.socialproject.mvp.ui.fragment;


import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.ninetaildemonfox.zdl.ninetaildemonfox.base.BaseFragment;
import com.ninetaildemonfox.zdl.socialproject.R;
import com.ninetaildemonfox.zdl.socialproject.mvp.contract.AccountDetailsContract;
import com.ninetaildemonfox.zdl.socialproject.mvp.presenter.AccountDetailsPresenter;
import com.ninetaildemonfox.zdl.socialproject.mvp.ui.fragment.adapter.AccountDetailsAdapter;
import com.ninetaildemonfox.zdl.socialproject.utils.ToastUtil;

import java.util.List;
import java.util.Map;

import butterknife.BindView;

/**
 * @author NineTailDemonFox
 * @date 2019/7/22 16:56
 * 功能描述： 账户明细
 * 联系方式：1037438704@qq.com
 */
public class AccountDetailsFragment extends BaseFragment implements AccountDetailsContract {

    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    private AccountDetailsAdapter accountDetailsAdapter;
    private AccountDetailsPresenter presenter;

    @Override
    protected int getLayoutResource() {
        return R.layout.fragment_account_details;
    }

    @Override
    protected void onInitView(Bundle savedInstanceState) {
        initView();
        initData();
    }

    private void initData() {
    }

    private void initView() {
        Bundle arguments = this.getArguments();
        int type = arguments.getInt("type");
        presenter = new AccountDetailsPresenter(this, fgtContext);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        accountDetailsAdapter = new AccountDetailsAdapter(R.layout.list_fragment_account_adp);
        recyclerView.setAdapter(accountDetailsAdapter);
        presenter.getBillList(token, String.valueOf(type), pageSize);
    }

    public static AccountDetailsFragment newInstance(int type) {
        AccountDetailsFragment dHomeFragment = new AccountDetailsFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("type", type);
        dHomeFragment.setArguments(bundle);
        return dHomeFragment;
    }

    @Override
    public void Success(List<Map<String, String>> list) {
        if (pageSize == 1) {
            accountDetailsAdapter.setNewData(list);
        } else {
            if (list == null) {
                ToastUtil.show("没有更多数据了");
                return;
            }
            accountDetailsAdapter.addData(list);
        }
    }

    @Override
    public void Failed(String msg) {

    }

    @Override
    public void showLoading() {
//        WaitDialog.show((AppCompatActivity) me,"数据加载中");
    }
}